package com.toggery.POS.controller;

import com.toggery.POS.service.*;
import com.toggery.POS.tool.Discount;
import com.toggery.POS.tool.InventoryType;
import com.toggery.POS.tool.OrderType;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

//页面跳转控制
@Controller
@Api(tags = "页面跳转")
public class ViewController {
    @Autowired
    ClothingService clothingService;
    @Autowired
    BrandService brandService;
    @Autowired
    CategoryService categoryService;
    @Autowired
    InventoryService inventoryService;
    @Autowired
    OrderService orderService;
    @Autowired
    RoleService roleService;
    @Autowired
    UserService userService;
    @RequestMapping("/test")
    public String test(){
        return "error/denied";
    }

//    @RequestMapping("/category")
//    public String category(){
//        return "category/category";
//    }
//    @RequestMapping("/category/add")
//    public String categoryForm(){
//        return "category/categoryForm";
//    }
    @RequestMapping("/user")
    public String user(){
        return "user/user";
    }
    @RequestMapping("/user/add")
    public String userAdd(Model model){
        model.addAttribute("role",roleService.findAll());
        return "user/add";
    }
    @RequestMapping("/user/edit")
    public String userEdit(Model model,@RequestParam String id){
        model.addAttribute("role",roleService.findAll());
        return "user/edit";
    }
    @RequestMapping("/bill")
    public String bill(){
        return "bill/bill";
    }
    @RequestMapping("/order")
    public String order(){
        return "order/order";
    }
    @RequestMapping("/order/add")
    public String order(Model model){
        return "order/add";
    }
    @RequestMapping("/order/addDetail")
    public String orderDetail(Model model,@RequestParam String id){
        model.addAttribute("orderId",id);
        model.addAttribute("clothing",clothingService.findAll());
        return "order/addDetail";
    }
    @RequestMapping("/order/show1")
    public String orderItems(Model model,@RequestParam String id){
        model.addAttribute("discount", Discount.list);
        model.addAttribute("id",id);
        if(orderService.findById(Integer.parseInt(id)).getOrdertype().trim().equals("未支付")){
            model.addAttribute("pay",1);
        }else {
            model.addAttribute("pay",0);
        }
        return "order/showItems";
    }
    @RequestMapping("/inventory")
    public String inventory(){
        return "inventory/inventory";
    }
    @RequestMapping("/inventory/add")
    public String inventoryAdd(Model model){
        model.addAttribute("clothing",clothingService.findAll());
        model.addAttribute("type", InventoryType.list);
        return "inventory/add";
    }
    @RequestMapping("/inventory/show1")
    public String inventoryItem(Model model,@RequestParam String id){
        model.addAttribute("id",id);
        return "inventory/showItems";
    }
    @RequestMapping("/inventory/show2")
    public String inventoryItems(){
        return "inventory/showItems2";
    }


    @RequestMapping("/clothing")
    public String clothing(){
        return "clothing/clothing";
    }
    @RequestMapping("/clothing/add")
    public String clothingAdd(Model model){
        model.addAttribute("brand",brandService.findAll());
        model.addAttribute("category",categoryService.findAll());
        return "clothing/add";
    }
    @RequestMapping("/clothing/edit")
    public String clothingEdit(Model model, @RequestParam String id){
        model.addAttribute("clothing",clothingService.findById(Integer.parseInt(id)));
        return "clothing/edit";
    }
    @RequestMapping("/brand")
    public String brand(){
        return "brand/brand";
    }
    @RequestMapping("/brand/add")
    public String brandAdd(){
        return "brand/add";
    }
    @RequestMapping("/brand/edit")//@RequestParam
    public String brandEdit(Model model, @RequestParam String id){
        model.addAttribute("brand",brandService.findById(Integer.parseInt(id)));
        return "brand/edit";
    }

}
